package cn.juque.lucenecandy.core.base;

import cn.hutool.core.util.ClassUtil;
import cn.juque.lucenecandy.core.constants.StrConstant;
import lombok.ToString;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TermQuery;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>IdQueryWrapperBuilder</li>
 * </ul>
 * @date 2023-12-26
 **/
@ToString
public class IdQueryWrapperBuilder<T extends BaseEntity> extends AbstractBuilder<T, IdQueryWrapperBuilder<T>> {

    public IdQueryWrapperBuilder(Class<T> indexClass, String id) {
        super(indexClass);
        super.queryMap.put(new TermQuery(new Term(StrConstant.D_ID, id)), BooleanClause.Occur.MUST);
    }

    /**
     * 添加排序规则
     *
     * @param sfunction 字段
     * @param type      类型
     * @param reverse   是否倒序
     * @return M
     */
    @Override
    public IdQueryWrapperBuilder<T> addSort(Sfunction<T, ?> sfunction, SortField.Type type, Boolean reverse) {
        return super.thisType;
    }

    @Override
    public IdQueryWrapper build() {
        return new IdQueryWrapper(ClassUtil.getClassName(super.indexClass, false),
                super.indexInfo, super.queryMap, super.fieldToLoad);
    }
}
